<?php
	class Group extends MY_Controller{
		
		public function __construct(){
			parent::__construct();
			$this->load->model('group_model');
		}
		
		public function index(){
			
				$data['group'] = $this->group_model->getGroupList();
				$data['title'] = "Group list";
				$this->load->view('templates/header1', $data);
				$this->load->view('group/index', $data);
				$this->load->view('templates/right', $data);
				$this->load->view('templates/footer');
			
		}
		
		public function displayForm($id=FALSE){
			
				$this->load->helper("form");
				$data = array();
				if($id!=FALSE){
					$data['group'] = $this->group_model->getGroupList($id);				
				}
				$data['title']="Create Group";
				$this->load->view('templates/header1', $data);
				$this->load->view('group/form', $data);
				$this->load->view('templates/right', $data);
				$this->load->view('templates/footer');
			
		}
		
		public function create(){
			$this->displayForm();
		}
		
		public function edit($id){
			$this->displayForm($id);
		}
		
		public function delete($id){
			$this->group_model->delete($id);
			redirect("group", "refresh");
		}
		
		public function save(){
			
				$this->load->helper("form");
				$this->load->library('form_validation');
				$this->form_validation->set_rules('name', 'Name', 'required');
				if ($this->form_validation->run() === FALSE){
					$data['title']="Create group";
					$this->load->view('templates/header1', $data);
					$this->load->view('group/form', $data);
					$this->load->view('templates/right', $data);
					$this->load->view('templates/footer');
				}
				else{
					$this->group_model->save();
					redirect("group", "refresh");
				}
			
		}
		
	}
?>